home *** CD-ROM | disk | FTP | other *** search
- unit TxtGrid;
-
- {more excellent but underdocumented code; this component lets you autosize
- columns as you set text into the FitCells[] property. A default spacing of
- 5 pixels from the end of the text to the gridline is in effect}
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Grids;
-
- type
- TTextGrid = class(TStringGrid)
- private
- fFromRight: Byte;
- fSuspendFit: Boolean;
- protected
- procedure SetFitCells(ACol, ARow: Integer; const Value: string);
- public
- constructor Create(aOwner:TComponent); override;
- property FitCells[ACol,ARow:Integer]: string write SetFitCells;
- published
- property FromRight: Byte read fFromRight write fFromRight default 5;
- property SuspendFit: Boolean read fSuspendFit write fSuspendFit;
- end;
-
- implementation
-
- constructor TTextGrid.Create(aOwner:TComponent);
- begin
- inherited create(aOwner);
- fFromRight:=5;
- DefaultColWidth:= 10;
- DefaultRowHeight:= 18;
- end;
-
- procedure TTextGrid.SetFitCells(ACol, ARow: Integer; const Value: string);
- var
- i:integer;
- begin
- if not fSuspendFit then begin
- i:=Canvas.textwidth(Value)+fFromRight;
- if ColWidths[aCol]<i then
- ColWidths[aCol]:=i;
- end;
- Cells[aCol,aRow]:=Value;
- end;
-
- end.
-